package com.example.guiadigital4;


import com.guiadigital4.entidades.Lugar;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private Lugar[] data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;
    
    public LazyAdapter(Activity a, Lugar[] d) {
        activity = a;
        data=d;     
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
        vi = inflater.inflate(R.layout.item, null);
        
        TextView text=(TextView)vi.findViewById(R.id.text);
        TextView des=(TextView)vi.findViewById(R.id.description);
        TextView tel=(TextView)vi.findViewById(R.id.tel);
        
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        Lugar actual=data[position];
        
        text.setText(actual.getNombre());
        des.setText("Direccion: "+actual.getDireccion());
        tel.setText("agregar");
        
        //image.setImageResource(R.drawable.ico_bar);
        imageLoader.DisplayImage(actual.getIcono(), image);
              
        return vi;
    }
}